<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform @deleteItem="deleteUserItem" ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr,errorModal} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js'
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userIdCacheKey: 'rps-hggfpj-tsupplierEvaluation-title6-userIdCacheKey',
			})
		},
		methods:{
			initLoad(){
				let _that = this
				
				_that.$nextTick(function(){
					if(_that.$refs.autoform.formdata.userId){
						_that.om.request(
							'orgInstPosUserOfficial/getPosComboboxByUser',
							{
								userId: _that.$refs.autoform.formdata.userId,
								flag: true
							},
						).then(res=>{
							_that.$refs.autoform.changeEditor("title6", "posId", "data", configSelectData(res,"id","posName"))
							_that.$refs.autoform.initSelectIndex("title6", "posId")
						})
					}else{
						_that.$refs.autoform.changeEditor("title6", "posId", "data", configSelectData([],"id","posName"))
						_that.$refs.autoform.initSelectIndex("title6", "posId")
					}
				})
			},
			clearUserId(){
				let _that = this
				_that.$refs.autoform.clear("title6",'userId')
				_that.$refs.autoform.clear("title6",'posId')
				_that.$refs.autoform.clear("title6",'instId')
			},
			onselectPosId(item){
				let _that = this
				_that.$refs.autoform.formdata.posId = item.id
				_that.$refs.autoform.formdata.posName = item.posName
				_that.$refs.autoform.formdata.instId = item.instId
				_that.$refs.autoform.formdata.instName = item.instName
			},
			clearPosId(){
				let _that = this
				_that.$refs.autoform.clear("title6",'posId')
				_that.$refs.autoform.clear("title6",'instId')
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.userIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.userId = d.id
							formdata.userName = d.username
							formdata.posId = d.salaryPosId
							formdata.posName = d.salaryPosName
							formdata.instId = d.salaryPosInstId
							formdata.instName = d.salaryPosInstName
							
							_that.$refs.autoform.changeEditor('title6', 'userId', {
								'link': '../../public/pageSearch/pageSearch',
								"linkParam": {
									url:'temployee/getStaffCombogrid',
									namefield: 'userPosInstName',
									other:JSON.stringify({
										firstId: d.id
									}),
									searchfield: "q",
									initload:true,
									cachename: _that.userIdCacheKey,
								}
							});
							
							_that.om.request(
								'orgInstPosUserOfficial/getPosComboboxByUser',
								{
									userId: d.id,
									flag: true
								},
							).then(res=>{
								_that.$refs.autoform.changeEditor("title6", "posId", "data", configSelectData(res,"id","posName"))
								_that.$refs.autoform.initSelectIndex("title6", "posId")
							})
							uni.removeStorage({
								key:_that.userIdCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								
								changeEditor('title6', "userId", {
									'link': '../../public/pageSearch/pageSearch',
									"linkParam": {
										url:'temployee/getStaffCombogrid',
										namefield: 'userPosInstName',
										other:JSON.stringify({
											firstId: _that.formdata.userId || ''
										}),
										searchfield: "q",
										initload:true,
										cachename: _that.userIdCacheKey,
									}
								}, null, _that.autoformdata)
								
								
								_that.initLoad()
								
								}
							}
						})
					}
				})
			}
		}
</script>

<style>
</style>